fix: Align start, end, and probability lists in ExtractiveReader#11347
Merged
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub. 1 Skipped Deployment
|
Contributor
Coverage reportClick to see where and how coverage changed
This report was generated by python-coverage-comment-action |
||||||||||||||||||||||||
Code reviewNo issues found. Checked for bugs and CLAUDE.md compliance. |
Member
|
|
Contributor
Author
Good catch! I added a comment. |
anakin87
reviewed
May 20, 2026
Co-authored-by: Stefano Fiorucci <stefanofiorucci@gmail.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Related Issues
ExtractiveReader.runwas raisingValueError: zip() argument 3 is longer than arguments 1-2whenever the number of valid answer spans for a sequence was smaller thananswers_per_seq(e.g. short documents, or any case where the defaultanswers_per_seq=20exceeded the number of non-masked upper-triangular (start, end) token pairs).Proposed Changes:
In _postprocess, filter each sequence's
candidates_valuesrow by the same valid mask and return alist[torch.Tensor](one 1D tensor per sequence, variable length) instead of a 2D tensor. The return-type annotation and the_nest_answersprobabilities parameter annotation were updated to match.Root cause
_postprocessfiltered the per-sequence start/end token-index lists byvalid = candidates_values[i] > 0, producing variable-length lists, but returned candidates_values as the unfiltered 2D tensor of shape(batch_size, answers_per_seq).How did you test it?
Added two unit tests in test/components/readers/test_extractive.py:
test_postprocess_filters_probs_when_answers_per_seq_exceeds_valid_spans:constructs a batch where
answers_per_seq=5exceeds the 3 valid upper-triangular spans, asserts all three returned per-sequence structures have matching length 3 and that retained probabilities are all > 0.test_nest_answers_accepts_variable_length_probability_rows:calls
_nest_answerswith probabilities as alist[Tensor]containing rows of length 2 and 1 (the new contract) andverifies scores flow through correctly.
Notes for the reviewer
Checklist
fix:,feat:,build:,chore:,ci:,docs:,style:,refactor:,perf:,test:and added!in case the PR includes breaking changes.